<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>显示设置</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css"/>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script src="/static/component/pear/module/ruinuo/sortable.js"></script>
    <script src="/static/component/pear/module/ruinuo/xm-select.js"></script>
</head>
<body>
<div class="view_body">
    <form class="layui-form" action="">
        <div class="ruinuo_box">
            <div class="main-container layui-row layui-col-space10 label_con">
                <fieldset class="layui-elem-field layui-field-title layui-col-xs12">
                    <legend class="tips_legend">显示设置</legend>
                </fieldset>
                <blockquote class="layui-elem-quote tips_legend layui-col-xs12">
                    字段编码填写英文、字段名称填写中文，宽度不填则默认最小宽度160px
                </blockquote>
                <div class="design-box layui-col-xs12 layui-col-md12 field_box">
                    <div class="layui-input-block  block_margin_left_0">
                        <textarea name="field" id="focus_1712541319_7" class="layui-input" style="display: none"
                                  lay-filter="json_filter"></textarea>
                        <div class="table_1712541319_7 f_table">
                            <table id="table_1712541319_7" lay-filter="filter_1712541319_7"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </form>

</div>

<script>
    let SettingData = {};
    let SeleteData = {};
    let menu_code = '';
    let raw = '';
    let InitData = {};
    let event_field=[];
    let $ = layui.jquery;
    layui.use(['form', 'http', 'public', 'engine_form'], function () {
        let fields=parent.layui.design_form.GetFieldData();
        fields.forEach(item=>{
            event_field.push({label:item.title+'_'+item.field,value:item.field});
        })
        init();
    })
    function init() {
        let Postdata=layui.public.GetQueryAll() || {};
        Postdata['mode_id']=$(".design-right-con select[name='mode_id']",window.parent.document).val() || '';
        layui.http.SendAjax('', Postdata, [], function (res) {
            InitData= res.data || [];
            InitData['source']['event_field']={rows:event_field};
            FormBind();
        })








    }
    function FormBind()
    {
        let data=$(".design-right-con textarea[name='cols']",window.parent.document).val() || '[]';
        $("#focus_1712541319_7").val(data);
        let tablefield = {
            "title": "字段",
            "field": "field",
            "tag": "jsontable",
            "type": "json",
            "required": 1,
            "verify": "json",
            "hide_label": 1,
            "elem_id": "1712541319_7",
            "cols": [
                {
                    "title": "字段编码",
                    "field": "field",
                    "update": "select",
                    "required": 1,
                    "options": "database_field",
                },{
                    "title": "字段名称",
                    "field": "title",
                    "update": "input",
                    "required": 1
                },{
                    "title": "对应携带参数",
                    "field": "form_field",
                    "update": "select",
                    "options": "event_field",
                },{
                    "title": "宽",
                    "field": "width",
                    "update": "input",
                },
                {
                    "title": "数据来源",
                    "field": "options",
                    "update": "select",
                    "options": "options_list",
                }
            ],
        };
        layui.engine_form.BindJsonTable(tablefield);
    }
    function SendForm()
    {
        let json = $("textarea[name='field']").val() || '[]';
        let fields=eval(json);
        let msg='';
        fields.forEach((item,index)=>{
            delete (item.LAY_NUM)
            delete (item.LAY_INDEX)
            let field=item.field || '';
            let title=item.title || '';
            let width=item.width || 0;
            if (field=='' || title=='')
            {
                msg='必填项不能为空'
            }
            if (Number(width)==0)
            {
                fields[index]['minWidth']=160;
            }
        })
        if (msg)
        {
            layui.layer.msg(msg, {icon: 2});
            return false;
        }
        return JSON.stringify(fields);
    }

</script>
</body>
</html>

